using System.Collections.Generic;
using WCell.Constants.Items;
using WCell.RealmServer.Items.Enchanting;
using WCell.Util;
using WCell.Util.Data;
using WCell.RealmServer.Content;

namespace WCell.RealmServer.Items
{
	public class ItemRandomPropertyEntry
	{
		public uint Id;
		public ItemEnchantmentEntry[] Enchants = new ItemEnchantmentEntry[ItemConstants.MaxEnchantsPerEntry];
	}

	public class ItemRandomSuffixEntry
	{
		public int Id;// 0

		public ItemEnchantmentEntry[] Enchants; // 19, 20, 21
		public int[] Values; // 22, 23, 24
	}

	public abstract class BaseItemRandomPropertyInfo : IDataHolder
	{
		public uint EnchantId;
		public ItemId ItemId;
		public float Chance;

		public abstract void FinalizeDataHolder();
	}

	[DataHolder]
	public class ItemRandomEnchantEntry : BaseItemRandomPropertyInfo
	{
		//[NotPersistent]
		//public ItemRandomPropertyEntry RandomPropEntry;

		public override void FinalizeDataHolder()
		{
			//RandomPropEntry = ItemMgr.GetRandomPropertyEntry(EntryId);
			var template = ItemMgr.GetTemplate(ItemId);
			if (template == null)
			{
				ContentHandler.OnInvalidDBData("RandomEnchantEntry has invalid ItemId: {0} ({1}) (Enchant: {2})", ItemId, (int)ItemId, EnchantId);
			}
			else
			{
				template.RandomEnchants.Add(this);
			}
		}
	}

	//[DataHolder]
	//public class ItemRandomSuffixInfo : BaseItemRandomPropertyInfo
	//{
	//    [NotPersistent]
	//    public ItemRandomSuffixEntry Entry;

	//    public override void FinalizeAfterLoad()
	//    {
	//        Entry = ItemMgr.GetRandomSuffixEntry(EntryId);

	//        var list = ArrayUtil.GetOrCreate(ref ItemMgr.RandomSuffixes, Id);
	//        list.Add(this);
	//    }
	//}
}
